package com.heiye.blog.ai.controller;

import com.heiye.blog.ai.model.vo.*;
import com.heiye.blog.ai.servie.RoleService;
import com.heiye.blog.framework.biz.operationlog.aspect.ApiOperationLog;
import com.heiye.blog.framework.common.response.Response;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * @author: heiye
 * @date: 2025/11/05 下午8:50
 * @version: v1.0.0
 * @description: 智能体业务
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping("/list")
    @ApiOperationLog(description = "查询智能体列表")
    Response<?> findRobotPageList(@RequestBody @Validated FindRolePageListReqVO findRolePageListReqVO) {
        return roleService.findRolePageList(findRolePageListReqVO);
    }

    @GetMapping("/findById")
    @ApiOperationLog(description = "查询智能体详情")
    Response<?> findById(@RequestParam Long id) {
        return roleService.findById(id);
    }


    @GetMapping("/findTextModel")
    @ApiOperationLog(description = "查询智能体文本模型")
    Response<?> findTextModelById(@RequestParam Long id) {
        return roleService.findRoleTextModelById(id);
    }

    /**
     * 流式对话
     *
     * @param aiRoleChatReqVO
     * @return
     */
    @PostMapping(value = "/chat/completion", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @ApiOperationLog(description = "角色流式对话")
    public Flux<AIResponse> chat(@RequestBody @Validated AIRoleChatReqVO aiRoleChatReqVO) {
        return roleService.chat(aiRoleChatReqVO);
    }

    /**
     * 生成声音
     *
     * @param soundGenerationReqVO
     * @return
     */
    @PostMapping("/sound/generation")
    @ApiOperationLog(description = "生成声音")
    public Response<?> soundGeneration(@RequestBody @Validated SoundGenerationReqVO soundGenerationReqVO) {
        return roleService.soundGeneration(soundGenerationReqVO);
    }

    @PostMapping("/chat/new")
    @ApiOperationLog(description = "新建角色对话")
    public Response<?> newRoleChat(@RequestBody @Validated NewRoleChatReqVO newRoleChatReqVO) {
        return roleService.newRoleChat(newRoleChatReqVO);
    }
}
